//
//  String+Extension.swift
//  sinaWeibo
//
//  Created by hjun on 16/3/31.
//  Copyright © 2016年 hjun. All rights reserved.
//

import Foundation

extension String{
    
    func sinaSource() -> String {
        
        let pattern = ">(.*?)<"
        
        let regular = try! NSRegularExpression(pattern: pattern, options: NSRegularExpressionOptions.DotMatchesLineSeparators)
        
        
        let result = regular.firstMatchInString(self, options: NSMatchingOptions(rawValue: 0), range: NSRange.init(location: 0, length: self.characters.count))
        
        ///配到的范围数量
        let count = result?.numberOfRanges ?? 0
        
        if count > 1{
            
            let range = result!.rangeAtIndex(1)
            
            return (self as NSString).substringWithRange(range)
        }
        
        return "未知来源"
    }
    
    
    
}